<template>
	<view class="content" v-if="pageShow">
		<u-sticky v-if="!shoptable_id">
			<view class="paddinglr padding_top3 fafafa">
				<view class="header flexbetween">
					<view :class="type==0?'selects':''" @click="type=0;" v-show="shopdata.is_ws==1">配送</view>
					<view :class="type==1?'selects':''" @click="type=1;changetab()" v-show="shopdata.is_zq==1">自取</view>
					<view :class="type==2?'selects':''" @click="type=2;changetab()" v-show="shopdata.is_ny==1">内用</view>
				</view>
			</view>
		</u-sticky>
		<view class="paddinglr">
			<view v-show="type==0">
				<view class="mainpadding margin_top ffffff border2 flexbetween" @click="selectAddress">
					<view v-show="username" class="flexbetween" style="width: 100%;">
						<view class="flex1">
							<view class="flexleft">
								<view class="text_w color_ling margin_right3">{{username}}</view>
								<view class="text_w color_ling margin_right3">{{mobile}}</view>
							</view>
							<view class="text_five color_six margin_top">
								{{useraddre}}
							</view>
						</view>
						<u-icon name="arrow-right" color="#999" size="16"></u-icon>
					</view>
					<view v-show="!username">
						<view class="flexcenter">
							<view class="text_w color_ling margin_right3">點擊選擇收貨地址</view>
						</view>
					</view>
				</view>
			</view>

			<!-- 地圖 -->
			<!-- <view class="mainpadding margin_top border2 ffffff" v-if="type!=0">
				<view class="text_w color_ling">地圖</view>
			</view> -->
			<!-- 自取時間 -->
			<view v-show="type==1">
				<view class="mainpadding margin_top border2 ffffff flexbetween">
					<view class="text_x color_ling">自取時間</view>
					<view class="flexleft" @click="show=true" v-if="issm!=1">
						<view class="text_a color_six margin_right2" v-show="!askfortime">請選擇</view>
						<view class="text_a color_theme margin_right2" v-show="askfortime">{{askfortime_text}}</view>
						<u-icon name="arrow-right" color="#999" size="16"></u-icon>
					</view>
					<view class="flexleft" v-if="issm==1">
						<view class="text_a color_theme" v-show="askfortime">{{askfortime_text}}</view>
					</view>
				</view>
				<view class="mainpadding margin_top border2 ffffff flexbetween">
					<view class="text_x color_ling">净重</view>
					<view class="" @click="scanbarCode()">
						<image class="scanImg" src="/static/images/index/scan.png" mode=""></image>
					</view>
				</view>
			</view>
			<view v-show="type==2">
				<!-- 使用號碼 -->
				<view class="" v-show="shoptable_id">
					<view class="mainpadding margin_top border2 ffffff flexbetween">
						<view class="text_x color_ling">使用號碼</view>
						<view class="text_a color_six margin_right2">{{shoptable_num}}</view>
					</view>
				</view>

				<!-- 到店時間 -->
				<view class="mainpadding margin_top border2 ffffff flexbetween">
					<view class="text_x color_ling">到店時間</view>
					<view class="flexleft" @click="show=true" v-if="issm!=1">
						<view class="text_a color_six margin_right2" v-show="!draktime">請選擇</view>
						<view class="text_a color_theme margin_right2" v-show="draktime">{{draktime_text}}</view>
						<u-icon name="arrow-right" color="#999" size="16"></u-icon>
					</view>
					<view class="flexleft" v-if="issm==1">
						<view class="text_a color_theme" v-show="draktime">{{draktime_text}}</view>
					</view>
				</view>
				<!-- 内用選擇人數 -->
				<view class="margin_top mainpadding ffffff border2">
					<view class="flexbetween padding_bottom border_bottom">
						<view class="color_ling text_x">客戶人數</view>
						<view class="numberBg">
							<u-number-box button-size="36" :min="0" color="#000000" bgColor="#F7F7F7"
								iconStyle="color: #fff" v-model="adult"></u-number-box>
						</view>
					</view>
					<view class="margin_top flexbetween padding_bottom border_bottom">
						<view class="color_ling text_x">老人人數</view>
						<view class="numberBg">
							<u-number-box button-size="36" :min="0" color="#000000" bgColor="#F7F7F7"
								iconStyle="color: #fff" v-model="old"></u-number-box>
						</view>
					</view>
					<view class="flexbetween margin_top">
						<view class="color_ling text_x">兒童人數</view>
						<view class="numberBg">
							<u-number-box button-size="36" :min="0" color="#000000" bgColor="#F7F7F7"
								iconStyle="color: #fff" v-model="child"></u-number-box>
						</view>
					</view>
				</view>
			</view>
			<view class="margin_top">
				<view class="mainpadding border2 ffffff margin_bottom3 positionr"
					v-for="item in orderInfo.goodscartdata" :key="item.id">
					<view class="flexleft">
						<view class="goodsImg margin_right3">
							<image :src="item.logoimage_text" mode=""></image>
						</view>
						<view class="number">{{item.salename}}</view>
						<view class="flex1 justify_between_column" style="height: 157rpx;">
							<view class="text_a color_san bold">{{item.goods_name}}</view>
							<view class="text_b color_six flexbetween margin_top1" v-if="item.wei || item.hei">
								<text>尺寸：{{item.wei}}*{{item.hei}}</text>
								<text>用量：{{item.formulacount}}{{item.size}}</text>
							</view>
							<view class="flexbetween">
								<view class="xiaolan" v-if="item.spunatdata_text && item.spunatdata_text.length">
									規格：<text class="margin_right1" v-for="(value) in item.spunatdata_text"
										:key="value.spunatid">{{value.spunatname}}*{{value.num}}</text></view>
								<view class="text_b xiaohuang" v-if="item.goodsdeail && item.goodsdeail.weight">
									重量：{{item.goodsdeail.weight}}</view>
							</view>
							<view class="flexbetween">
								<view class="price">${{item.d_price}}&nbsp;&nbsp;&nbsp;x{{item.num}}</view>
								<view class="text_six color_orange">${{item.price}}</view>
							</view>
						</view>
					</view>
					<view class="xiaolan smalltext margin_top" v-if="item.childdata.length">商品規格一</view>
					<view class="flexleft margin_top1" v-for="ite in item.childdata" :key="ite.id">
						<view class="goodsImg margin_right3">
							<image :src="ite.logoimage_text" mode=""></image>
						</view>
						<view class="number" v-if="ite.salename">{{ite.salename}}</view>
						<view class="flex1 justify_between_column" style="height: 157rpx;">
							<view class="text_a color_san bold">{{ite.goods_name}}</view>
							<view class="text_b color_six flexbetween margin_top1" v-if="ite.wei || ite.hei">
								<text>尺寸：{{ite.wei}}*{{ite.hei}}</text>
								<text>用量：{{ite.formulacount}}{{ite.size}}</text>
							</view>
							<view class="xiaolan" v-if="ite.spunatdata_text && ite.spunatdata_text.length">規格：<text
									class="margin_right1" v-for="(value) in ite.spunatdata_text"
									:key="value.spunatid">{{value.spunatname}}*{{value.num}}</text></view>
							<view class="flexbetween">
								<view class="price">${{ite.d_price || 0}}&nbsp;&nbsp;&nbsp;x{{ite.num}}</view>
								<view class="text_six color_orange">${{ite.price}}</view>
							</view>
						</view>
					</view>
				</view>
				<view class="textright">
					<text class="text_b color_san margin_right2">共計{{orderInfo.goodscartdata.length}}件商品</text>
					<text v-show="type==2">
						<text class="text_b color_san ">服務費</text>
						<text
							class="text_b color_orange margin_right2">${{Math.round(total_price * fwrotate / 100)}}</text>
						<text class="text_b color_san">合計</text>
						<text
							class="text_b color_orange">${{Number(total_price) + Math.round(total_price * fwrotate / 100)}}</text>
					</text>
					<text v-show="type==0 || type==1">
						<text class="text_b color_san">合計</text>
						<text class="text_b color_orange">${{total_price}}</text>
					</text>
				</view>
			</view>
			<!-- 配送費 -->
			<view class="" v-show="type==0 && orderInfo.shopfreight.length">
				<view class="mainpadding margin_top ffffff border2">
					<view class="text_w color_ling">配送方式<text class="xiaohong"
							v-show="Number(total_price)>=Number(shopdata.deliveryfee) && shopdata.deliveryfee!==''">訂單金額已滿{{shopdata.deliveryfee}}本次訂單配送免費</text>
					</view>
					<view class="flexbetween margin_top" v-for="item in orderInfo.shopfreight" :key="item.id">
						<view class="text_a color_six" v-show="item.type==0">{item.name}
							<text v-show="shopdata.deliveryfee!=0">固定：${{item.money_g}}</text>
						</view>
						<view class="text_a color_six" v-show="item.type==1">{{item.name}} <text v-show="shopdata.deliveryfee!=0"> 免運費</text></view>
						<view class="text_a color_six" v-show="item.type==2">{{item.name}} <text v-show="shopdata.deliveryfee!=0"> 固定：${{item.money_g}}滿${{item.money_count}}=${{item.money_jian}}</text>
							</view>
						<view :class="item.isChecked?'xuanzhongs':'wiexuanzhongs'" @click="selectFreight(item)"></view>
					</view>
				</view>
			</view>
			<!-- 優惠券 -->
			<!-- <view class="mainpadding margin_top border2 ffffff flexbetween" @click="selectyhqFn()">
				<view class="text_x color_ling">優惠券</view>
				<view class="flexleft">
					<view class="text_a color_theme margin_right2" v-show="rall_id">抵扣{{yh_money}}</view>
					<view class="text_a color_six margin_right2" v-show="!rall_id">請選擇</view>
					<u-icon name="arrow-right" color="#999" size="16"></u-icon>
				</view>
			</view> -->
			<!-- 儲值 -->
			<!-- <view class="mainpadding margin_top border2 ffffff "
				v-if="orderInfo.shopUser && orderInfo.shopUser.money!=0" @click="chuzhichecked=!chuzhichecked">
				<view class="flexbetween">
					<view class="text_x color_ling titletext">儲值餘額：<text
							class="hong_text titletext bold">${{orderInfo.shopUser.money}}</text></view>
					<view :class="chuzhichecked?'xuanzhongs':'wiexuanzhongs'"></view>
				</view>
				<view class="margin_top totalPrice"
					v-if="orderInfo.shopUser && orderInfo.shopUser.money!=0 && chuzhichecked">
					<text class="text_x color_ling titletext">儲值抵扣：</text><text
						class="hong_text">-${{Number(orderInfo.shopUser.money)-Number(paymoney)>=0?Number(paymoney):Number(orderInfo.shopUser.money)}}</text>
				</view>
			</view> -->
			<!-- 免運券 -->
			<!-- <view class="" v-show="type==0">
				<view class="mainpadding margin_top border2 ffffff flexbetween" @click="selectmyqFn()">
					<view class="text_x color_ling">免運券</view>
					<view class="flexleft">
						<view class="text_a color_theme margin_right2" v-show="ship_id">{{ship_name}}</view>
						<view class="text_a color_six margin_right2" v-show="!ship_id">請選擇</view>
						<u-icon name="arrow-right" color="#999" size="16"></u-icon>
					</view>
				</view>
			</view> -->
			<view class="mainpadding_top ffffff line_b9" v-if="orderInfo.shop.appkey && orderInfo.shop.is_sdkfp==0">
				<view class="text_weight color_san white_nowrap">發票類型
					<!-- <text style="color: #ff0000;">*</text> -->
				</view>
				<view class="margin_top flexbetween">
					<view :class="opentype==0?'flexleft select':'flexleft noSelect'" @click="opentype=0">
						<image class="vote1Img"
							:src="opentype==0?'@/static/images/mine/vote1_active.png':'@/static/images/mine/vote1.png'"
							mode=""></image>
						<view>紙本</view>
					</view>
					<view :class="opentype==1?'flexleft select':'flexleft noSelect'" @click="opentype=1;tbcode=zjcode;">
						<image class="vote2Img"
							:src="opentype==1?'@/static/images/mine/vote2_active.png':'@/static/images/mine/vote2.png'"
							mode=""></image>
						<view>載具</view>
					</view>
					<view :class="opentype==2?'flexleft select':'flexleft noSelect'"
						@click="opentype=2;tbcode=tbcode1;">
						<image class="vote3Img"
							:src="opentype==2?'@/static/images/mine/vote3_active.png':'@/static/images/mine/vote3.png'"
							mode=""></image>
						<view>統編</view>
					</view>
					<view :class="opentype==3?'flexleft select':'flexleft noSelect'" @click="opentype=3;tbcode=jzcode;">
						<image class="vote4Img"
							:src="opentype==3?'@/static/images/mine/vote4_active.png':'@/static/images/mine/vote4.png'"
							mode=""></image>
						<view>捐贈</view>
					</view>
				</view>
				<view class="invoiceInput margin_top flexbetween" v-show="opentype!=0">
					<input class="text_b" type="text" placeholder="請輸入手機載具" v-show="opentype==1" v-model="tbcode">
					<input class="text_b" type="text" placeholder="請輸入統一編碼" @blur="getTt()" v-show="opentype==2"
						v-model="tbcode">
					<input class="text_b" type="text" placeholder="請輸入捐贈碼" v-show="opentype==3" v-model="tbcode">
					<view class="" v-show="opentype==1 || opentype==3" @click="getCode()">
						<u-icon name="scan" color="#ffb800" size="28"></u-icon>
					</view>
				</view>
				<view class="invoiceInput margin_top" v-show="opentype==2">
					<input class="text_b" type="text" placeholder="請輸入發票抬頭" v-model="tbmc">
				</view>
			</view>
			<!-- 備注 -->
			<view class="mainpadding margin_top ffffff border2">
				<view class="text_w color_ling">備注</view>
				<textarea class="textareas text_five margin_top" placeholder-style="font-size: 26rpx;color: #999999;"
					cols="30" rows="10" placeholder="請輸入備注信息" v-model="ordernotes"></textarea>
			</view>
			
		</view>
		<!-- 底部 -->
		<view class="footerBox">
			<view class="footerPirce flexbetween">
				<view class="flexleft paddingtb padding_left3">
					<view>
						<text class="text_j color_ling">合計：</text>
						<text class="totalPrice">$</text>
						<text class="totalPrice" style="font-size: 36rpx;"
							v-if="chuzhichecked">{{Number(orderInfo.shopUser.money)-Number(paymoney)>0?0:Number(paymoney)-Number(orderInfo.shopUser.money)}}</text>
						<text class="totalPrice" style="font-size: 36rpx;" v-else>{{paymoney}}</text>
					</view>
				</view>
				<view class="flexleft">
					<view class="settlement" @click="addOrder">結帳</view>
				</view>
			</view>
		</view>
		<u-datetime-picker cancelText="取消" confirmText="確認" :show="show" v-model="value1" :minDate="Number(new Date())"
			mode="datetime" confirmColor="#FFB800" @cancel="show=false" @confirm="confirmTime"></u-datetime-picker>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				chuzhichecked: false,
				show: false,
				value1: Number(new Date()),
				shop_id: uni.getStorageSync("shop_id"),
				buycar_id: "", //購物車id
				orderInfo: {},
				pageShow: false,
				total_price: 0,

				type: 0, //訂單類型:0=配送,1=自取,2=内用
				username: "", //用戶姓名
				mobile: "", //用戶電話
				sheng: "",
				shi: "",
				qu: "",
				useraddre: "", //用戶地址
				shopfreight_id: "", //物流ID
				ordernotes: "", //訂單備注
				askfortime: "", //自取時間
				askfortime_text: "", //自取時間-展示
				draktime: "", //内用用餐時間
				draktime_text: "", //内用用餐時間-展示
				adult: 0, //成人人數
				old: 0, //老人人數
				child: 0, //兒童人數
				freightPrice: 0, //選擇的配送費
				shopdata: '',
				latitude: "",
				longitude: "",
				yh_money: "",
				rall_id: "",
				ship_id: "",
				shoptable_id: "", //使用id
				shoptable_num: "",
				opentype: 0, //開票類型 0紙本 1載具 2統編 3捐贈
				tbcode: "", //開票内容
				tbcode1: "",
				jzcode: "",
				zjcode: "",
				tbmc: "",
				issm: 0,
				ship_name: "",
				issubmit: false,
				fwrotate: 0, //服務費比例
				fwprice: 0, //服務費
				userInfo: {}
			}
		},
		watch: {
			// orderInfo(newval) {
			// 	if (this.orderInfo.shopUser && this.orderInfo.shopUser.money != 0) {
			// 		this.chuzhichecked = true
			// 	}
			// }
		},
		computed: {
			paymoney() {
				let total_price = 0
				if (this.type == 2) {
					total_price = Number(this.total_price) + Math.round(this.total_price * this.fwrotate / 100)
				} else {
					total_price = this.total_price
				}
				if (this.ship_id || (Number(total_price) >= Number(this.shopdata.deliveryfee) && this.shopdata
						.deliveryfee !== '')) {
					return (Number(total_price) - Number(this.yh_money)) < 0 ? 0 : Number(total_price) - Number(
						this.yh_money)
				} else {
					return (Number(total_price) - Number(this.yh_money) + Number(this.freightPrice)) < 0 ? 0 : Number(
						total_price) - Number(this.yh_money) + Number(this.freightPrice)
				}
			}
		},
		onUnload() {
			uni.$off("returnCode")
		},
		onLoad(options) {
			uni.$on("returnCode", data => {
				this.tbcode = data
			})
			this.buycar_id = options.buycar_id
			if (options.issm != 0) {
				this.issm = options.issm
				this.draktime_text = this.http.timereturn(Number(new Date()))
				this.draktime = this.millisecond(Number(new Date()))
				this.askfortime_text = this.http.timereturn(Number(new Date()))
				this.askfortime = this.millisecond(Number(new Date()))
			}
			console.log(this.buycar_id)
			this.getInfo()
			this.getuserInfo()
			if (uni.getStorageSync("zth")) {
				this.shoptable_id = uni.getStorageSync("zth")
				this.shoptable_num = uni.getStorageSync("ztnum")
				uni.setStorageSync("zth", "")
				uni.setStorageSync("ztnum", "")
				this.type = 2
				this.draktime_text = this.http.timereturn(Number(new Date()))
				this.draktime = this.millisecond(Number(new Date()))
			}
		},
		onShow() {
			uni.$off("selectAddressFn")
			uni.$on("selectAddressFn", data => {
				this.username = data.name
				this.mobile = data.phone
				this.latitude = data.latitude
				this.longitude = data.longitude
				let shengshiqi = data.addre.split('/')
				this.sheng = shengshiqi[0]
				this.shi = shengshiqi[1]
				this.qu = shengshiqi[2]
				this.useraddre = data.address
			})
			uni.$off("selectyhq")
			uni.$on("selectyhq", data => {
				this.yh_money = data.yh_money
				this.rall_id = data.rall_ids
			})
			uni.$off("selectmyq")
			uni.$on("selectmyq", data => {
				this.ship_id = data.ship_id
				this.ship_name = data.name
			})
		},
		methods: {
			getCode() {
				uni.navigateTo({
					url: "/pages_mine/getcodetwm"
				})
			},
			getTt() {
				if (this.opentype != 2) {
					return false
				}
				this.http.request("/api/user/getTbmc", "GET", {
					tbcode: this.tbcode
				}).then(res => {
					if (res.code == 1) {
						this.tbmc = res.data.tbinfo.name
					}
				})
			},
			async getuserInfo() {
				let res = await this.http.request('/api/member/userInfo', 'GET', {})
				if (res.data.opentype != 0) {
					this.opentype = res.data.opentype
				}
				if (res.data.jzcode) {
					this.jzcode = res.data.jzcode
					this.tbcode = res.data.jzcode
				}
				if (res.data.tbcode) {
					this.tbcode = res.data.tbcode
					this.tbcode1 = res.data.tbcode
				}
				if (res.data.zjcode) {
					this.zjcode = res.data.zjcode
					this.tbcode = res.data.zjcode
				}
				if (this.opentype == 2) {
					this.tbcode = res.data.tbcode
				}
				uni.setStorageSync("invite_code", res.data.invite_code)
				this.tbmc = res.data.tbmc
				this.userInfo = res.data
			},
			changetab() {
				this.orderInfo.shopfreight.forEach(item => {
					item.isChecked = false
				})
				this.shopfreight_id = ""
				this.freightPrice = 0
			},
			selectyhqFn() {
				let total_price = 0
				if (this.type == 2) {
					total_price = Number(this.total_price) + Math.round(this.total_price * this.fwrotate / 100)
				} else {
					total_price = this.total_price
				}
				uni.navigateTo({
					url: "/pages_mine/mineCoupon?type=1&allprice=" + total_price + "&shop_id=" + this.shop_id
				})
			},
			selectmyqFn() {
				uni.navigateTo({
					url: "/pages_mine/minemyq?type=1&allprice=" + total_price + "&shop_id=" + this.shop_id
				})
			},
			async getInfo() { //訂單詳情
				let _this = this
				let res = await this.http.request('/api/ordergoods/sureGoodsOrder', 'GET', {
					shop_id: this.shop_id,
					// buycar_id: this.buycar_id
				})
				if (res.code == 1) {
					let price = 0
					res.data.goodscartdata.forEach(item => {
						price += Number(item.price)
					})
					this.total_price = price
					this.shopdata = res.data.shop
					if (new Date().getDay() == 1) this.fwrotate = this.shopdata.motime_rate //周一
					if (new Date().getDay() == 2) this.fwrotate = this.shopdata.tutime_rate //周二
					if (new Date().getDay() == 3) this.fwrotate = this.shopdata.wetime_rate //周三
					if (new Date().getDay() == 4) this.fwrotate = this.shopdata.thtime_rate //周四
					if (new Date().getDay() == 5) this.fwrotate = this.shopdata.frtime_rate //周五
					if (new Date().getDay() == 6) this.fwrotate = this.shopdata.satime_rate //周六
					if (new Date().getDay() == 0) this.fwrotate = this.shopdata.sutime_rate //周日
					if (this.shopdata.is_ws == 1 && !this.shoptable_id) {
						this.type = 0
					} else if (this.shopdata.is_zq == 1 && !this.shoptable_id) {
						this.type = 1
					} else if (this.shopdata.is_ny == 1 && !this.shoptable_id) {
						this.type = 2
					}
					res.data.shopfreight.forEach(item => {
						this.$set(item, "isChecked", false)
					})
					if (res.data.useraddres) {
						this.username = res.data.useraddres.name
						this.mobile = res.data.useraddres.phone
						let shengshiqi = res.data.useraddres.addre.split('/')
						this.sheng = shengshiqi[0]
						this.shi = shengshiqi[1]
						this.qu = shengshiqi[2]
						this.useraddre = res.data.useraddres.address
					}

					this.orderInfo = res.data
					this.pageShow = true
				} else if (res.code == 0) {
					// this.http.toast(res.msg)
				} else {
					this.http.toast('系統處理中，請稍後再試');
				}
			},
			selectAddress() { //選擇地址
				uni.navigateTo({
					url: "/pages_mine/takeAddress?type=1"
				})
			},
			confirmTime(e) { //自取時間、到店時間
				console.log(e.value);
				if (this.type == 1) {
					// this.askfortime = this.secondDate(e.value, 0, 1)
					this.askfortime = this.millisecond(e.value)
					this.askfortime_text = this.secondDate(e.value, 0, 1)
				} else if (this.type == 2) {
					this.draktime = this.millisecond(e.value)
					this.draktime_text = this.secondDate(e.value, 0, 1)
				}
				this.show = false
			},
			selectFreight(item) { //選擇配送費
				if (item.type == 0) {
					this.freightPrice = item.money_g
				} else if (item.type == 1) {
					this.freightPrice = 0
				} else {
					if (Number(this.total_price) >= Number(item.money_count)) {
						this.freightPrice = item.money_jian
					} else {
						this.freightPrice = item.money_g
					}
				}
				this.orderInfo.shopfreight.forEach(item => {
					item.isChecked = false
				})
				item.isChecked = true
			},
			addOrder() { //提交訂單
				if (!this.userInfo.nickname || !this.userInfo.username || !this.userInfo.email) {
					this.http.toast("請完善個人信息后操作")
					return false
				}
				if (this.type == 0) {
					if (this.useraddre == "") {
						this.http.toast("請選擇收貨地址")
						return false
					}
				}
				this.orderInfo.shopfreight.forEach(item => {
					if (item.isChecked) {
						this.shopfreight_id = item.id
					}
				})
				if (this.type == 0) {
					this.draktime = ""
					this.askfortime = ""
				}
				if (this.type == 0 && !this.shopfreight_id && this.orderInfo.shopfreight.length) {
					this.http.toast("請選擇配送費")
					return false
				}
				if (this.type == 1) {
					this.draktime = ""
					this.shopfreight_id = ""
				} else if (this.type == 2) {
					this.askfortime = ""
					this.shopfreight_id = ""
				}
				if (this.type == 1 && !this.askfortime) {
					this.http.toast("請選擇自取時間")
					return false
				}
				if (this.type == 2 && !this.draktime) {
					this.http.toast("請選擇到店時間")
					return false
				}
				if (this.type == 2) {
					let allnum = Number(this.adult) + Number(this.old) + Number(this.child)
					if (allnum == 0) {
						this.http.toast("到店人數不能爲0")
						return false
					}
				}
				
				if (this.type == 2 && this.shoptable_id == "") {
					this.http.modal('内用', "下單完成后請到訂單掃二維碼入座", false, (resp) => {
						this.submittj()
					})
					return false
				}
				this.submittj()
			},
			async submittj() {
				if (this.issubmit) return
				this.issubmit = true
				let fw_price = 0
				if (this.type == 2) { //内用
					fw_price = Math.round(this.total_price * this.fwrotate / 100)
				}
				let countmoney = this.paymoney
				let flag = false //是否向上提交发票信息
				if (this.orderInfo.shop.appkey) {
					if (this.orderInfo.shop.is_sdkfp == 0) {
						flag = true
					}
				} else {
					flag = false
				}
				let url = "/api/ordergoods/addOrder"
				let data = {
					shop_id: this.shop_id,
					type: this.type, //訂單類型:0=配送,1=自取,2=内用
					askfortime: this.askfortime, //自取時間
					draktime: this.draktime, //内用用餐時間
					adult: this.adult, //成人人數
					old: this.old, //老人人數
					child: this.child, //兒童人數
					countnum: "", //總計數量
					countmoney,
					paymoney: this.paymoney, //實际支付金額
					username: this.username, //用戶姓名
					ship_id: this.ship_id, //免運券id
					yh_money: this.yh_money, //優惠金額
					rall_id: this.rall_id, //優惠券id
					mobile: this.mobile, //用戶電話
					useraddre: this.useraddre, //用戶地址
					sheng: this.sheng, //用戶地址
					shi: this.shi, //用戶地址
					qu: this.qu, //用戶地址
					ordernotes: this.ordernotes, //訂單備注
					latitude: this.latitude,
					longitude: this.longitude,
					shopfreight_id: "", //物流ID
					document: "", //訂單文档
					opentype: flag ? this.opentype : -1,
					tbcode: flag ? this.tbcode : '',
					tbmc: flag ? this.tbmc : '',
					freight_price: this.freightPrice,
					shop_user_price: 0,
					fw_price
				}
				console.log(data.countmoney, "hahah");
				if (this.chuzhichecked) { //如果儲值抵扣勾選了價格要改一下
					data.paymoney = Number(this.orderInfo.shopUser.money) - Number(this.paymoney) >= 0 ? 0 : Number(
						this.paymoney) - Number(this.orderInfo.shopUser.money);
					data.shop_user_price = Number(this.orderInfo.shopUser.money) - Number(this.paymoney) >= 0 ? Number(
						this.paymoney) : Number(this.orderInfo.shopUser.money);
				}
				if (this.shoptable_id) {
					this.$set(data, "shoptable_id", this.shoptable_id)
				}
				let res = await this.http.request(url, 'POST', data)
				if (res.code == -1) {
					this.http.toast(res.msg)
					setTimeout(() => {
						uni.navigateTo({
							url: "/pages_mine/personInformation"
						})
					}, 1000)
					return false
				}
				if (res.code == 1) {
					uni.removeStorageSync("zth")
					if (data.paymoney == 0) {
						uni.switchTab({
							url: "/pages/index/index"
						})
					} else {
						// type 0配送。1自取，2内用 
						// sktype 1先收款，2后收款
						if (this.type == 2 && this.shoptable_id == "" && this.issm==1) {
							uni.switchTab({
								url: "/pages/index/index"
							})
						} else {
							uni.redirectTo({
								url: "/pages_index/payment?msg=" + encodeURIComponent(JSON.stringify({
									id: res.data.id,
									paymoney: this.paymoney,
									shop_id: this.shop_id,
									shoptable_id: this.shoptable_id,
									call_no: res.data.call_no,
									issm: this.issm
								}))
							})
						}
					}
				} else {
					this.issubmit = false
					this.http.toast(res.msg)
				}
			}
		}
	}
</script>
<style lang="scss" scoped>
	.scanImg {
		width: 42rpx;
		height: 42rpx;
	}

	.content {
		padding-bottom: 180rpx;
	}

	.header {
		padding: 6rpx;
		box-sizing: border-box;
		background: #F1F1F1;
		border-radius: 72rpx 72rpx 72rpx 72rpx;
		font-size: 30rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;

		view {
			width: 25%;
			text-align: center;
		}

		.selects {
			width: 25%;
			height: 88rpx;
			line-height: 88rpx;
			text-align: center;
			background: #ffb800;
			border-radius: 72rpx 72rpx 72rpx 72rpx;
			font-size: 30rpx;
			font-family: PingFang SC-Heavy, PingFang SC;
			font-weight: 800;
			color: #000000;
		}
	}

	.goodsImg {
		width: 157rpx;
		height: 157rpx;
		position: relative;

		image {
			width: 100%;
			height: 100%;
			border-radius: 14rpx;
		}

	}

	.number {
		padding: 5rpx 30rpx;
		background: rgba(255, 133, 5, 0.1);
		border-radius: 0rpx 14rpx 0rpx 14rpx;
		position: absolute;
		top: 0;
		right: 0;
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FF8505;
	}

	.freeBox {
		width: 75rpx;
		height: 41rpx;
		line-height: 41rpx;
		text-align: center;
		background: rgba(255, 133, 5, .1);
		border-radius: 3rpx 3rpx 3rpx 3rpx;
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FF8505;
	}

	.price {
		font-size: 30rpx;
		font-family: DIN Next LT Pro-Bold, DIN Next LT Pro;
		font-weight: bold;
		color: #FF5C00;
	}

	.textareas {
		width: 100%;
		box-sizing: border-box;
		height: 150rpx;
		// padding: 30rpx;
		border-radius: 8rpx;
		// border: 2rpx solid #EFEFEF;
	}

	.numberBg {
		background: #F7F7F7;
		padding: 8rpx 6rpx;
		border-radius: 10rpx 10rpx 10rpx 10rpx;
	}

	::v-deep.u-number-box__minus {
		background-color: #EC7AA0 !important;
	}

	::v-deep.u-number-box__plus {
		background-color: #EC7AA0 !important;
	}

	::v-deep.uicon-minus {
		color: #fff !important;
	}

	::v-deep.uicon-plus {
		color: #fff !important;
	}

	// 底部
	.footerBox {
		width: 100%;
		padding: 0 30rpx;
		box-sizing: border-box;
		position: fixed;
		left: 0;
		bottom: 40rpx;

		.footerPirce {
			width: 708rpx;
			height: 101rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 0rpx 14rpx 0rpx rgba(0, 0, 0, 0.05);
			border-radius: 53rpx 53rpx 53rpx 53rpx;
		}

		.cart {
			width: 40.5rpx;
			height: 42.58rpx;
			background-image: url("@/static/images/index/cart_num.png");
			background-size: 100% 100%;
			position: relative;
		}

		.num {
			width: 35rpx;
			height: 35rpx;
			line-height: 35rpx;
			text-align: center;
			background: #FF5C00;
			border-radius: 50%;
			position: absolute;
			right: -20rpx;
			top: -20rpx;
			font-size: 17rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
		}

		.line_r {
			width: 0;
			height: 42rpx;
			border-right: 2rpx dashed rgba(0, 0, 0, 1);
		}

		.totalPrice {
			font-size: 26rpx;
			font-family: DIN Next LT Pro-Medium;
			font-weight: 500;
			color: rgba(253, 70, 62, 1);
		}

		.copy {
			width: 160rpx;
			height: 101rpx;
			line-height: 101rpx;
			text-align: center;
			background: #FF8505;
			border-radius: 53rpx 0 0 53rpx;
			font-size: 32rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #ffffff;
		}

		.settlement {
			width: 145rpx;
			height: 101rpx;
			line-height: 101rpx;
			text-align: center;
			background: #FFB800;
			border-radius: 0rpx 53rpx 53rpx 0rpx;
			font-size: 32rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #000000;
		}
	}

	.vote1Img {
		width: 26rpx;
		height: 26rpx;
		margin-left: 20rpx;
		margin-right: 10rpx;
	}

	.vote2Img {
		width: 23.5rpx;
		height: 23.5rpx;
		margin-left: 20rpx;
		margin-right: 10rpx;
	}

	.vote3Img {
		width: 29rpx;
		height: 29rpx;
		margin-left: 20rpx;
		margin-right: 10rpx;
	}

	.vote4Img {
		width: 27rpx;
		height: 27rpx;
		margin-left: 20rpx;
		margin-right: 10rpx;
	}


	.noSelect {
		width: 154rpx;
		height: 69rpx;
		text-align: center;
		line-height: 69rpx;
		background: rgba(102, 102, 102, .1);
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		border: 2rpx solid rgba(102, 102, 102, .1);
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	.select {
		width: 154rpx;
		height: 69rpx;
		text-align: center;
		line-height: 69rpx;
		background: rgba(255, 133, 5, 0.1);
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		border: 2rpx solid #FF8505;
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FF8505;
		position: relative;
	}

	.select::after {
		content: '';
		width: 25rpx;
		height: 20rpx;
		position: absolute;
		right: 0;
		bottom: 0;
		background-image: url('/static/images/mine/invoice_select.png');
		background-size: 100% 100%;
	}

	.invoiceInput {
		width: 100%;
		height: 91rpx;
		background: rgba(196, 196, 196, .1);
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		display: flex;
		align-items: center;
		padding-left: 20rpx;

		input {
			width: 80%;
		}
	}
</style>